/**
 * @copyright SilverBiology, LLC
 * @author SilverBiology, LLC
 * @website http://www.silverbiology.com
*/
Ext.ns("BioBlitz");

BioBlitz.HybridPanel = function(config){

	this.marker = null;
	
	this.dataentryPanel = new BioBlitz.GeoInfoPanel({
				width: 300
			,	dock: 'left'
	});
			
	this.dataentryPanel.on("locationFound", this.addMarkerToMap, this);	
	this.dataentryPanel.on('resetmap', this.resetMap, this);	

	this.myMapPanel = new BioBlitz.HybridMapPanel({ 
			width: "100%"
		,	lat: config.lat
		,	lon: config.lon
		,	zoom: config.zoom
	});

	Ext.apply(this, config, { 
			title: 'Data Entry'
		,	iconCls: 'download'
		,	dockedItems: [{
						dock: 'top'
					,	xtype: 'toolbar'
					,	title: 'Data Entry'
				}, this.dataentryPanel
			]
		,	items: [
				this.myMapPanel
			]
	});
		
	BioBlitz.HybridPanel.superclass.constructor.call(this, config);

};

Ext.extend(BioBlitz.HybridPanel , Ext.Panel, {
		
		addMarkerToMap: function( coord ){
//console.log( this, a, b, c );
			var point = new google.maps.LatLng( coord.latitude, coord.longitude );
			
			if (this.marker != null) {
				this.marker.setMap(null);
			}

			this.marker = new google.maps.Marker({
					position: point
				,	draggable : true
				,	id: 'marker'
				,	map: this.myMapPanel.map
			});		
		
			this.myMapPanel.map.setCenter(point);
			this.myMapPanel.map.setZoom(15);
				
			google.maps.event.addListener(this.marker, "dragend", function(point){
				Ext.getCmp('latitude').setValue( point.latLng.b );
				Ext.getCmp('longitude').setValue( point.latLng.c );
			});
/*				
			var infowindow = new google.maps.InfoWindow({
				content: 'Marker Information'
			});
*/			
/*				
			google.maps.event.addListener(this.marker, 'click', function(){
					infowindow.open(this.map, this);
			});
*/			
		}

	,	resetMap: function(){
			if (this.marker != null) {
				this.marker.setMap( null );
			}
		}

});	